<script language="javascript">
function validasi(form){
  if (form.nama.value == ""){
    alert("Anda belum mengisikan Nama.");
    form.nama.focus();
    return (false);
  }    
  if (form.alamat.value == ""){
    alert("Anda belum mengisikan Alamat.");
    form.alamat.focus();
    return (false);
  }
  if (form.telpon.value == ""){
    alert("Anda belum mengisikan Telpon.");
    form.telpon.focus();
    return (false);
  }
  if (form.email.value == ""){
    alert("Anda belum mengisikan Email.");
    form.email.focus();
    return (false);
  }
  if (form.jasa.value == 0){
    alert("Anda belum memilih jasa pengiriman barang.");
    form.jasa.focus();
    return (false);
  }
  if (form.kota.value == 0){
    alert("Anda belum mengisikan Kota.");
    form.kota.focus();
    return (false);
  }
  return (true);
}


function harusangka(jumlah){
  var karakter = (jumlah.which) ? jumlah.which : event.keyCode
  if (karakter > 31 && (karakter < 48 || karakter > 57))
    return false;

  return true;
}


$(document).ready(function() {
	$('#jasa').change(function() { 
		var category = $(this).val();
		$.ajax({
			type: 'GET',
			url: 'config/kota.php',
			data: 'perusahaan=' + category, // Untuk data di MySQL dengan menggunakan kata kunci tsb
			dataType: 'html',
			beforeSend: function() {
				$('#kota').html('<tr><td colspan=2>Loading ....</td></tr>');	
			},
			success: function(response) {
				$('#kota').html(response);
			}
		});
    });
});

</script>

<?php
// Halaman utama (Home)
if ($_GET['module']=='store'){
  echo "<div class='rotating_banner'>
              <div class='anythingSlider'>
                  <div class='wrapper'>
                    <ul>";
                        $header=mysql_query("SELECT * FROM header ORDER BY id_header DESC LIMIT 4");
                        while($b=mysql_fetch_array($header)){
                          echo "<li><img width=700 src='header/$b[gambar]'></li>";
                        }
                   echo "</ul>
                  </div>
              </div>
            </div>";
  // echo "<h4 class='heading colr2'>==========</h4>";
  $sql = mysql_query("SELECT * FROM produk ORDER BY id_produk DESC LIMIT 12");
  while ($r = mysql_fetch_array($sql)){
    $harga      = format_rupiah($r[harga]);
    $disc       = ($r[diskon]/100)*$r[harga];
    $hargadisc  = number_format(($r[harga]-$disc),0,",",".");
    $stok       = $r['stok'];
    $tombolbeli = "<a class='prod_cart' href=\"aksi.php?module=keranjang&act=tambah&id=$r[id_produk]\">BUY</a>";
    $tombolhabis="<span class='prod_cart_habis'></span>";
    
    if ($stok!= "0") $tombol = $tombolbeli;
    else $tombol = $tombolhabis;
    
    $d            = $r['diskon'];
    $hargatetap   = "<div class='prod_price'><span class='price'> <br /></span>&nbsp;<span class='price'> Rp. <b>$hargadisc,-</b></span></div></div>";
    $hargadiskon  = "<div class='prod_price'><span style='text-decoration:line-through;' class='price'>Rp. $harga,- <br /></span>&nbsp;<span class='price3'>Diskon $r[diskon]% 
	                   <br /><span class='price2'>Rp. <b>$hargadisc,-</b></span></div></div>";
    
    if ($d!= "0") $divharga=$hargadiskon;
    else $divharga=$hargatetap;
    
    echo "<div class='prod_box'>
          <div class='top_prod_box'></div> 
          <div class='center_prod_box'>            
             <div class='product_title'><a href='produk-$r[id_produk]-$r[produk_seo].html'>$r[nama_produk]</a></div>
             <div class='product_img'>
                             <a href='produk-$r[id_produk]-$r[produk_seo].html'><a href='foto_produk/$r[gambar]' rel='clearbox[gallery=Koleksi Produk]' title='$r[nama_produk]'>
               <img src='foto_produk/$r[gambar]' border='0' height=110 width=114  class='tooltip' title='Click to enlarge image'></a>
             </div>
             $divharga
          <div class='bottom_prod_box'></div>
          <div class='prod_details_tab'>
             $tombol            
             <a href='produk-$r[id_produk]-$r[produk_seo].html' class='prod_details'>DETAIL</a> 
          </div>
          </div>";
  }
}


// Modul detail produk
else if ($_GET['module']=='detailproduk'){

	$detail=mysql_query("SELECT * FROM produk,kategori    
                      WHERE kategori.id_kategori=produk.id_kategori 
                      AND id_produk='$_GET[id]'");
	$d   = mysql_fetch_array($detail);
	$tgl = tgl_indo($d[tanggal]);


    $harga = format_rupiah($d[harga]);
    $disc     = ($d[diskon]/100)*$d[harga];
    $hargadisc     = number_format(($d[harga]-$disc),0,",",".");


	echo "<h4 class='heading colr'>Kategori: <a href='kategori-$d[id_kategori]-$d[kategori_seo].html'>$d[nama_kategori]</a></h4></div>";

	echo"<div class='feat_prod_box_details'>";
 	if ($d['gambar'] != '') {
		echo "<div class='prod_img3'><a href='foto_produk/$d[gambar]' rel='clearbox[gallery=Koleksi Produk]' title='$d[nama_produk]'<img src='foto_produk/$d[gambar]' width=180  class='tooltip' title='Click to enlarge image' border='0' rel='clearbox[gallery=Koleksi Produk]' title='$d[nama_produk]'/></a></div>";
  }
	  echo"<div class='details_big_box'>
          <div class='product_title_big'>$d[nama_produk]</div>
          <div class='details'>$d[deskripsi]</div><br />
                  <div class='table6'>&bull; HARGA: <span class='table7'>Rp. $hargadisc,-</span></div>
		        
                  <div class='table6'>&bull; STOK:<span class='table7'> $d[stok] item</span></div><br />
                  <a href='aksi.php?module=keranjang&act=tambah&id=$d[id_produk]' class='more'><img src='images/beli.gif' alt='' title='' border='0' /></a>
                  <div class='box_bottom'></div>
              </div> <div class='clear'></div>
          </div><br /> ";
// Produk Lainnya (random)          
  $sql = mysql_query("SELECT * FROM produk ORDER BY rand() LIMIT 4");
      
  echo "<h4 class='heading colr'>Produk Lainnya</h4>";
  
  while ($r=mysql_fetch_array($sql)){
    $harga        = format_rupiah($r[harga]);
    $disc         = ($r[diskon]/100)*$r[harga];
    $hargadisc    = number_format(($r[harga]-$disc),0,",",".");
    $stok         = $r['stok'];
    $tombolbeli   = "<a class='prod_cart' href=\"aksi.php?module=keranjang&act=tambah&id=$r[id_produk]\">BUY</a>";
    $tombolhabis  = "<span class='prod_cart_habis'></span>";
    
    if ($stok!= "0") $tombol=$tombolbeli;
    else $tombol=$tombolhabis;
      
    $d            = $r['diskon'];
    $hargatetap   = "<div class='prod_price'><span class='price'> <br /></span>&nbsp;<span class='price'> Rp. <b>$hargadisc,-</b></span></div></div>";
    $hargadiskon  = "<div class='prod_price'><span style='text-decoration:line-through;' class='price'>Rp. $harga,- <br /></span>&nbsp;<span class='price3'>Diskon $r[diskon]% 
	                   <br /><span class='price2'>Rp. <b>$hargadisc,-</b></span></div></div>";
    
    if ($d!= "0") $divharga=$hargadiskon;
    else $divharga=$hargatetap;
      
    echo "<div class='prod_box'>
          <div class='top_prod_box'></div> 
          <div class='center_prod_box'>            
             <div class='product_title'><a href='produk-$r[id_produk]-$r[produk_seo].html'>$r[nama_produk]</a></div>
             <div class='product_img'>
               <a href='produk-$r[id_produk]-$r[produk_seo].html'><a href='produk-$r[id_produk]-$r[produk_seo].html'><a href='foto_produk/$r[gambar]' rel='clearbox[gallery=Koleksi Produk]' title='$r[nama_produk]'>
               <img src='foto_produk/$r[gambar]' border='0' height=110 width=114  class='tooltip' title='Click to enlarge image'></a>
             </div>
             $divharga
          <div class='bottom_prod_box'></div>
          <div class='prod_details_tab'>
             $tombol            
             <a href='produk-$r[id_produk]-$r[produk_seo].html' class='prod_details'>DETAIL</a>            
          </div> 
          </div>";
  }
  echo "<div class=halaman>&nbsp;</div><br>";
}

// Modul produk per kategori
else if ($_GET['module']=='baru'){
  echo "<h4 class='heading colr'>New Product</h4>";

  // Tentukan berapa data yang akan ditampilkan per halaman (paging)
  $p      = new Paging3;
  $batas  = 12;
  $posisi = $p->cariPosisi($batas);

  // Tampilkan daftar produk yang sesuai dengan kategori yang dipilih
 	$sql = mysql_query("SELECT * FROM produk 
            ORDER BY id_produk DESC LIMIT $posisi,$batas");		 
	$jumlah = mysql_num_rows($sql);

	// Apabila ditemukan produk dalam kategori
	if ($jumlah > 0){
  while ($r = mysql_fetch_array($sql)){
    $harga        = format_rupiah($r[harga]);
    $disc         = ($r[diskon]/100)*$r[harga];
    $hargadisc    = number_format(($r[harga]-$disc),0,",",".");
    $stok         = $r['stok'];
    $tombolbeli   = "<a class='prod_cart' href=\"aksi.php?module=keranjang&act=tambah&id=$r[id_produk]\">BUY</a>";
    $tombolhabis  = "<span class='prod_cart_habis'></span>";
    
    if ($stok != "0")  $tombol = $tombolbeli;
    else $tombol = $tombolhabis;
      
    $d            = $r['diskon'];
    $hargatetap   = "<div class='prod_price'><span class='price'> <br /></span>&nbsp;<span class='price'> Rp. <b>$hargadisc,-</b></span></div>";
    $hargadiskon  = "<div class='prod_price'><span style='text-decoration:line-through;' class='price'>Rp. $harga,- <br /></span>&nbsp;<span class='price3'>Diskon $r[diskon]% 
	                   <br /><span class='price2'>Rp. <b>$hargadisc,-</b></span></div>";
   
    if ($d != "0") $divharga = $hargadiskon;
    else $divharga = $hargatetap;
    
    echo "<div class='prod_box'>
            <div class='top_prod_box'></div> 
            <div class='center_prod_box'>            
               <div class='product_title'><a href='produk-$r[id_produk]-$r[produk_seo].html'>$r[nama_produk]</a></div>
               <div class='product_img'>
                 <a href='produk-$r[id_produk]-$r[produk_seo].html'><a href='produk-$r[id_produk]-$r[produk_seo].html'><a href='foto_produk/$r[gambar]' rel='clearbox[gallery=Koleksi Produk]' title='$r[nama_produk]'>
                 <img src='foto_produk/$r[gambar]' border='0' height=110 width=114  class='tooltip' title='Click to enlarge image'></a>
               </div>
               $divharga
            </div>
            <div class='bottom_prod_box'></div>
            <div class='prod_details_tab'>
               $tombol            
               <a href='produk-$r[id_produk]-$r[produk_seo].html' class='prod_details'>DETAIL</a>            
            </div> 
          </div>";
  }

  $jmldata     = mysql_num_rows(mysql_query("SELECT * FROM produk WHERE id_kategori='$_GET[id]'"));
  $jmlhalaman  = $p->jumlahHalaman($jmldata, $batas);
  $linkHalaman = $p->navHalaman($_GET[halkategori], $jmlhalaman);

  echo "<div class=halaman>Halaman : $linkHalaman </div><br>";
  }
  else echo "<p align=left><span class='table7'>Belum ada produk pada kategori ini.</p>";
}


// Modul produk per kategori
else if ($_GET['module']=='detailkategori'){
  // Tampilkan nama kategori
  $sq = mysql_query("SELECT nama_kategori from kategori where id_kategori='$_GET[id]'");
  $n = mysql_fetch_array($sq);

  echo "<h4 class='heading colr'>Kategori: $n[nama_kategori]</h4>";

  // Tentukan berapa data yang akan ditampilkan per halaman (paging)
  $p      = new Paging3;
  $batas  = 12;
  $posisi = $p->cariPosisi($batas);

  // Tampilkan daftar produk yang sesuai dengan kategori yang dipilih
 	$sql = mysql_query("SELECT * FROM produk WHERE id_kategori='$_GET[id]' 
            ORDER BY id_produk DESC LIMIT $posisi,$batas");		 
	$jumlah = mysql_num_rows($sql);

	// Apabila ditemukan produk dalam kategori
	if ($jumlah > 0){
  while ($r = mysql_fetch_array($sql)){
    $harga        = format_rupiah($r[harga]);
    $disc         = ($r[diskon]/100)*$r[harga];
    $hargadisc    = number_format(($r[harga]-$disc),0,",",".");
    $stok         = $r['stok'];
    $tombolbeli   = "<a class='prod_cart' href=\"aksi.php?module=keranjang&act=tambah&id=$r[id_produk]\">BUY</a>";
    $tombolhabis  = "<span class='prod_cart_habis'></span>";
    
    if ($stok != "0")  $tombol = $tombolbeli;
    else $tombol = $tombolhabis;
      
    $d            = $r['diskon'];
    $hargatetap   = "<div class='prod_price'><span class='price'> <br /></span>&nbsp;<span class='price'> Rp. <b>$hargadisc,-</b></span></div>";
    $hargadiskon  = "<div class='prod_price'><span style='text-decoration:line-through;' class='price'>Rp. $harga,- <br /></span>&nbsp;<span class='price3'>Diskon $r[diskon]% 
	                   <br /><span class='price2'>Rp. <b>$hargadisc,-</b></span></div>";
   
    if ($d != "0") $divharga = $hargadiskon;
    else $divharga = $hargatetap;
    
    echo "<div class='prod_box'>
            <div class='top_prod_box'></div> 
            <div class='center_prod_box'>            
               <div class='product_title'><a href='produk-$r[id_produk]-$r[produk_seo].html'>$r[nama_produk]</a></div>
               <div class='product_img'>
                 <a href='produk-$r[id_produk]-$r[produk_seo].html'><a href='produk-$r[id_produk]-$r[produk_seo].html'><a href='foto_produk/$r[gambar]' rel='clearbox[gallery=Koleksi Produk]' title='$r[nama_produk]'>
                 <img src='foto_produk/$r[gambar]' border='0' height=110 width=114  class='tooltip' title='Click to enlarge image'></a>
               </div>
               $divharga
            </div>
            <div class='bottom_prod_box'></div>
            <div class='prod_details_tab'>
               $tombol            
               <a href='produk-$r[id_produk]-$r[produk_seo].html' class='prod_details'>DETAIL</a>            
            </div> 
          </div>";
  }

  $jmldata     = mysql_num_rows(mysql_query("SELECT * FROM produk WHERE id_kategori='$_GET[id]'"));
  $jmlhalaman  = $p->jumlahHalaman($jmldata, $batas);
  $linkHalaman = $p->navHalaman($_GET[halkategori], $jmlhalaman);

  echo "<div class=halaman>Halaman : $linkHalaman </div><br>";
  }
  else echo "<p align=left><span class='table7'>Belum ada produk pada kategori ini.</p>";
}

// Menu utama di header

// Modul profil
else if ($_GET['module']=='profilkami'){
  // Data profil mengacu pada id_modul=43
	$profil = mysql_query("SELECT * FROM modul WHERE id_modul='43'");
	$r      = mysql_fetch_array($profil);

  echo "<h4 class='heading colr'>Profil Kami</h4>
    	  <div class='prod_box_bigx'></div>
        <div class='profil'>
                <div>$r[static_content]</div>
			          <div class='bottom_prod_box_big4'></div>
        </div>";                             
}

// Modul hasil poling
else if ($_GET['module']=='hasilpoling'){
 echo "<div id='content'>          
          <div id='content-detail'>";
 if (isset($_COOKIE["poling"])) {
   echo "<span class='idtanggal'>Maaf, anda sudah pernah melakukan jajak pendapat ini.";
 }
 else{
  // membuat cookie dengan nama poling
  // cookie akan secara otomatis terhapus dalam waktu 24 jam
  setcookie("poling", "sudah poling", time() + 3600 * 24);
  echo "<h4 class='heading colr'>Hasil Polling</h4></div>";

  echo "<p align=left><span class='pol1'>Terima kasih atas partisipasi anda mengikuti polling kami<br /><br />
       Hasil polling saat ini: </p><br />";
  
  echo "<table width=600px style='border: 1pt dashed #ccc ;padding: 10px;'>";

  $jml=mysql_query("SELECT SUM(rating) as jml_vote FROM poling WHERE aktif='Y'");
  $j=mysql_fetch_array($jml);
  
  $jml_vote=$j[jml_vote];
  
  $sql=mysql_query("SELECT * FROM poling WHERE aktif='Y' and status='Jawaban'");
  
  while ($s=mysql_fetch_array($sql)){
  	
  	$prosentase = sprintf("%2.1f",(($s[rating]/$jml_vote)*100));
  	$gbr_vote   = $prosentase * 3;

    echo "<tr><td width=200><span class='pol2'>$s[pilihan] ($s[rating]) </td><td> 
          <img src=images/red.jpg width=$gbr_vote height=18 border=0> $prosentase % 
          </td></tr>";  
  }
  echo "</table>
        <p><span class='pol1'>Jumlah Pemilih: <span class='pol2'>$jml_vote</b></p>";
 }
  echo "</div>
    </div>";            
}


// Modul hasil poling
else if ($_GET['module']=='lihatpoling'){
  echo "<div id='content'>          
          <div id='content-detail'>";
  echo "<h4 class='heading colr'>Hasil Polling</h4></div>";

  echo "<p align=left><span class='pol1'>Terima kasih atas partisipasi anda mengikuti polling kami<br /><br />
       Hasil polling saat ini: </p><br />";
  
  echo "<table width=600px style='border: 1pt dashed #ccc ;padding: 10px;'>";

  $jml=mysql_query("SELECT SUM(rating) as jml_vote FROM poling WHERE aktif='Y'");
  $j=mysql_fetch_array($jml);
  
  $jml_vote=$j[jml_vote];
  
  $sql=mysql_query("SELECT * FROM poling WHERE aktif='Y' and status='Jawaban'");
  
  while ($s=mysql_fetch_array($sql)){
  	
  	$prosentase = sprintf("%2.1f",(($s[rating]/$jml_vote)*100));
  	$gbr_vote   = $prosentase * 3;

    echo "<tr><td width=200><span class='pol2'>$s[pilihan] ($s[rating]) </td><td> 
          <img src=images/red.jpg width=$gbr_vote height=18 border=0> $prosentase % 
          </td></tr>";  
  }
  echo "</table>
        <p><span class='pol1'>Jumlah Pemilih: <span class='pol2'>$jml_vote</b></p>";
  echo "</div>
    </div>";            
}

// Modul cara pembelian
else if ($_GET['module']=='carabeli'){
  // Data cara pembelian mengacu pada id_modul=45
	$cara = mysql_query("SELECT * FROM modul WHERE id_modul='45'");
	$r      = mysql_fetch_array($cara);

  echo "<h4 class='heading colr'>Cara Pembelian</h4>
        <div class='carabeli'>
              <div>$r[static_content]</div>
        </div>    
        ";                             
}

// Modul semua download
else if ($_GET['module']=='semuadownload'){

  echo "<h4 class='heading colr'>Download Katalog</h4>"; 
  $p      = new Paging5;
  $batas  = 20;
  $posisi = $p->cariPosisi($batas);
  // Tampilkan semua download
 	$sql = mysql_query("SELECT * FROM download  
                      ORDER BY id_download DESC LIMIT $posisi,$batas");		  
   while($d=mysql_fetch_array($sql)){
      echo "<p class='download'><a href='downlot.php?file=$d[nama_file]'>&bull; $d[judul]</a> <span class='download2'>(didownload: $d[hits]x)</p>";
	 }

	
  $jmldata     = mysql_num_rows(mysql_query("SELECT * FROM download"));
  $jmlhalaman  = $p->jumlahHalaman($jmldata, $batas);
  $linkHalaman = $p->navHalaman($_GET[haldownload], $jmlhalaman);

 echo "<div class='halaman'>Halaman : $linkHalaman </div>";
        
}

// Modul semua produk
else if ($_GET['module']=='semuaproduk'){
  echo "<h4 class='heading colr'>Semua Produk</h4>";

  // Tentukan berapa data yang akan ditampilkan per halaman (paging)
  $p      = new Paging2;
  $batas  = 16;
  $posisi = $p->cariPosisi($batas);

  // Tampilkan semua produk
  $sql=mysql_query("SELECT * FROM produk ORDER BY id_produk DESC LIMIT $posisi,$batas");

  while ($r=mysql_fetch_array($sql)){
    $harga = format_rupiah($r[harga]);
    $disc     = ($r[diskon]/100)*$r[harga];
    $hargadisc     = number_format(($r[harga]-$disc),0,",",".");
    $stok=$r['stok'];
    $tombolbeli="<a class='prod_cart' href=\"aksi.php?module=keranjang&act=tambah&id=$r[id_produk]\">BUY</a>";
    $tombolhabis="<span class='prod_cart_habis'></span>";
      if ($stok!= "0"){
      $tombol=$tombolbeli;
      }else{
      $tombol=$tombolhabis;
      } 

    $d=$r['diskon'];
    $hargatetap="<div class='prod_price'><span class='price'> <br /></span>&nbsp;<span class='price'> Rp. <b>$hargadisc,-</b></span></div>                        
          </div>";
    $hargadiskon="<div class='prod_price'><span style='text-decoration:line-through;' class='price'>Rp. $harga,- <br /></span>&nbsp;<span class='price3'>Diskon $r[diskon]% 
	 <br /><span class='price2'>Rp. <b>$hargadisc,-</b></span></div>                        
          </div>";
      if ($d!= "0"){
      $divharga=$hargadiskon;
      }else{
      $divharga=$hargatetap;
      } 

    echo "<div class='prod_box'>
          <div class='top_prod_box'></div> 
          <div class='center_prod_box'>            
             <div class='product_title'><a href='produk-$r[id_produk]-$r[produk_seo].html'>$r[nama_produk]</a></div>
             <div class='product_img'>
               <a href='produk-$r[id_produk]-$r[produk_seo].html'><a href='foto_produk/$r[gambar]' rel='clearbox[gallery=Koleksi Produk]' title='$r[nama_produk]'>
               <img src='foto_produk/$r[gambar]' border='0' height=110 width=114  class='tooltip' title='Click to enlarge image'></a>
             </div>
             $divharga
          <div class='bottom_prod_box'></div>
          <div class='prod_details_tab'>
             $tombol            
             <a href='produk-$r[id_produk]-$r[produk_seo].html' class='prod_details'>DETAIL</a>            
          </div> 
          </div>";

  }  
    
  $jmldata     = mysql_num_rows(mysql_query("SELECT * FROM produk"));
  $jmlhalaman  = $p->jumlahHalaman($jmldata, $batas);
  $linkHalaman = $p->navHalaman($_GET[halproduk], $jmlhalaman);

  echo "<div class='halaman'>Halaman : $linkHalaman </div>";
}

// Modul keranjang belanja
else if ($_GET['module']=='whislist'){
  // Tampilkan produk-produk yang telah dimasukkan ke keranjang belanja
  // $sid = session_id();
  $sql = mysql_query("SELECT * FROM orders_temp left join produk 
                      on orders_temp.id_produk=produk.id_produk
                      WHERE orders_temp.id_customer='$_SESSION[id_customer]' and orders_temp.id_customer<>0");
  $ketemu=mysql_num_rows($sql);
  if($ketemu < 1){
    echo "<script>window.alert('Keranjang Belanjanya masih kosong. Silahkan Anda berbelanja terlebih dahulu');
        window.location=('index.php')</script>";
    }
  else{  
  
    echo "<h4 class='heading colr'>View Whislist</h4>
          <form method=post action=aksi.php?module=keranjang&act=update>
            <table width=670 border=0 cellpadding=0 cellspacing=1 align=center>
              <tbody>
                <tr  background='images/bg_tab.jpg' align=center height=23><th><span class='table'>No</th>
        <th><span class='table'>Product</th><th><span class='table'>Product Name</th><th><span class='table'>Weight(Kg)</th><th><span class='table'>Qty</th>
                <th><span class='table'>Price</th><th><span class='table'>Sub Total</th><th>
                <span class='table'></th></tr>";  
  
  $no=1;
  while($r=mysql_fetch_array($sql)){
    $disc        = ($r[diskon]/100)*$r[harga];
    $hargadisc   = number_format(($r[harga]-$disc),0,",",".");
    $subtotal    = ($r[harga]-$disc) * $r[jumlah];
    $total       = $total + $subtotal;  
    $subtotal_rp = format_rupiah($subtotal);
    $total_rp    = format_rupiah($total);
    $harga       = format_rupiah($r[harga]);
   
    
       echo "<tr background='images/bg_tab2.jpg'  align=center><td><span class='table2'>$no</td><input type=hidden name=id[$no] value=$r[id_orders_temp]>
              <td align=center><a href='produk-$r[id_produk]-$r[produk_seo].html'><a href='foto_produk/$r[gambar]' rel='clearbox[gallery=Koleksi Produk]' title='$r[nama_produk]'><img width=80 class='imgcart' src=foto_produk/$r[gambar]  class='tooltip' title='Click to enlarge image'></td>
              <td><span class='table2'>$r[nama_produk]</td>
              <td align=center><span class='table2'>$r[berat]</td>
              <td><input type=text name='jml[$no]' value=$r[jumlah] size=1 onchange=\"this.form.submit()\" onkeypress=\"return harusangka(event)\"></td>
              <td><span class='table2'>$hargadisc</td>
              <td><span class='table2'>$subtotal_rp</td>
              <td align=center>
                <a href='aksi.php?module=keranjang&act=hapus&id=$r[id_orders_temp]'><img src=images/kali.png border=0 title=Hapus> Remove</a> <br><br>
                <a href='aksi.php?module=keranjang&act=addchart&id=$r[id_orders_temp]'><img width=13px src=images/add.gif border=0 title=Whislist> Add to Chart</a>
              </td>
          </tr>";
    $no++; 
  } 
  echo "<tr><td colspan=6 align=right><br><span class='table3'>Total:</td><td colspan=2><br><span class='table3'>Rp. $total_rp,-</b></td></tr>
        </tbody>
  </table>";
  

  }
} 

// Modul keranjang belanja
else if ($_GET['module']=='keranjangbelanja'){
  // Tampilkan produk-produk yang telah dimasukkan ke keranjang belanja
	$sid = session_id();
	$sql = mysql_query("SELECT * FROM orders_temp, produk 
			                WHERE id_session='$sid' and (orders_temp.id_customer=0 or orders_temp.id_customer is null)  AND orders_temp.id_produk=produk.id_produk");
  $ketemu=mysql_num_rows($sql);
  if($ketemu < 1){
    echo "<script>window.alert('Keranjang Belanjanya masih kosong. Silahkan Anda berbelanja terlebih dahulu');
        window.location=('index.php')</script>";
    }
  else{  
  
    echo "<h4 class='heading colr'>View Cart</h4>
          <form method=post action=aksi.php?module=keranjang&act=update>
		        <table width=670 border=0 cellpadding=0 cellspacing=1 align=center>
              <tbody>
                <tr  background='images/bg_tab.jpg' align=center height=23><th><span class='table'>No</th>
				<th><span class='table'>Product</th><th><span class='table'>Product Name</th><th><span class='table'>Weight(Kg)</th><th><span class='table'>Qty</th>
                <th><span class='table'>Price</th><th><span class='table'>Sub Total</th><th>
                <span class='table'></th></tr>";  
  
  $no=1;
  while($r=mysql_fetch_array($sql)){
    $disc        = ($r[diskon]/100)*$r[harga];
    $hargadisc   = number_format(($r[harga]-$disc),0,",",".");
    $subtotal    = ($r[harga]-$disc) * $r[jumlah];
    $total       = $total + $subtotal;  
    $subtotal_rp = format_rupiah($subtotal);
    $total_rp    = format_rupiah($total);
    $harga       = format_rupiah($r[harga]);
   
    
       echo "<tr background='images/bg_tab2.jpg'  align=center><td><span class='table2'>$no</td><input type=hidden name=id[$no] value=$r[id_orders_temp]>
              <td align=center><a href='produk-$r[id_produk]-$r[produk_seo].html'><a href='foto_produk/$r[gambar]' rel='clearbox[gallery=Koleksi Produk]' title='$r[nama_produk]'><img width=80 class='imgcart' src=foto_produk/$r[gambar]  class='tooltip' title='Click to enlarge image'></td>
              <td><span class='table2'>$r[nama_produk]</td>
       			  <td align=center><span class='table2'>$r[berat]</td>
              <td><input type=text name='jml[$no]' value=$r[jumlah] size=1 onchange=\"this.form.submit()\" onkeypress=\"return harusangka(event)\"></td>
              <td><span class='table2'>$hargadisc</td>
              <td><span class='table2'>$subtotal_rp</td>
              <td align=center>
                <a href='aksi.php?module=keranjang&act=hapus&id=$r[id_orders_temp]'><img src=images/kali.png border=0 title=Hapus> Remove</a> <br><br>
                <a href='aksi.php?module=keranjang&act=whist&id=$r[id_orders_temp]'><img width=13px src=images/add_wish.gif border=0 title=Whislist> Whistlist</a>
              </td>
          </tr>";
    $no++; 
  } 
  echo "<tr><td colspan=6 align=right><br><span class='table3'>Total:</td><td colspan=2><br><span class='table3'>Rp. $total_rp,-</b></td></tr>
        <tr><td colspan=2><br /><a href=javascript:history.go(-1)><input style='width: 135px; height: 22px;' type=submit  class= simplebtn value='Continue Shoping'></a><br /></td>
        <td colspan=2><br /><input style='width: 130px; height: 22px;' type=submit  class= simplebtn value='Update Cart'><br /></td>
        <td colspan=4 align=right><br /><a href=selesai-belanja.html style='width:100px; height: 22px;padding:10px' class= simplebtn>Proceed to Checkout<br /></td></tr>
        </tbody>
  </table>";
  echo "<br /><br /><br /><br /><p>
        *  	If you change the quantity (Qty), do not forget to press the button <b>Update Cart</b> <br />
        **  The total price above does not include postage which will be calculated when <b>Checkout</b></p><br />";             

  }
}    

// Modul login customer
else if ($_GET['module'] == 'login'){

  echo "<h4 class='heading colr'>Login</h4>"; 
  echo "
        <div class='table5'>
          <table width='100%' style='border: 0pt dashed #0000CC;padding: 10px;'>
          <form action=login-aksi.html method=POST>
          <tr><td><span class='table4'>Email:</td><td>  <input type=text class='isikoment3' name=email size=40></td></tr>
          <tr><td><span class='table4'>Password:</td><td>  <input type=password class='isikoment3' name=password size=40></td></tr>          
          </td><td colspan=2><p style='padding-top:15px ;'><input style=' width: 85px; height: 23px;' type=submit  class=simplebtn value='Login'></td></tr>
          </form></table><br />
        </div>";
  echo "<h4 class='heading colr'>Register</h4>"; 
  echo "
        <div class='table5'>
          <table width='100%' style='border: 0pt dashed #0000CC;padding: 10px;'>
          <form action=register-aksi.html method=POST>
          <tr><td><span class='table4'>Name:</td><td>  <input type=text class='isikoment3' name=name size=40></td></tr>
          <tr><td><span class='table4'>Address:</td><td>  <input type=text class='isikoment3' name=address size=40></td></tr>          
          <tr><td><span class='table4'>Phone:</td><td>  <input type=text class='isikoment3' name=phone size=40></td></tr>
          <tr><td><span class='table4'>Email:</td><td>  <input type=text class='isikoment3' name=email size=40></td></tr>          
          <tr><td><span class='table4'>Password:</td><td>  <input type=password class='isikoment3' name=password size=40></td></tr>          
          <tr><td>&nbsp;</td><td><img src='captcha.php'></td></tr>
          <tr><td>&nbsp;</td><td><span class=isikomen>(masukkan 6 kode di atas)<br /><input type=text class='isikoment3' name=kode size=10 maxlength=6><br /></td></tr>
          </td><td colspan=2><p style='padding-top:15px ;'><input style=' width: 85px; height: 23px;' type=submit  class=simplebtn value='Register'></td></tr>
          </form></table><br />
        </div>";
}

// Modul logout customer
else if ($_GET['module'] == 'logout'){
  $_SESSION['id_customer']     = 0;
  echo "<script>window.location='index.php'</script>";
     exit(0);
}

// module login
else if ($_GET['module']=='loginaksi'){
  $sql="select * from customer where email='$_POST[email]' and password=md5('$_POST[password]')";
  // echo $sql;exit();
  $s=mysql_query($sql);
  // echo mysql_num_rows($s);
  if(mysql_num_rows($s)==1){
    $r=mysql_fetch_array($s);
    $_SESSION['id_customer']=$r['id'];
    echo "<script>window.location='index.php'</script>";
  }else{
    echo "<script> alert('Email or password wrong');window.location='login.html'</script>\n";
  }
}

// Modul hubungi aksi
else if ($_GET['module']=='registeraksi'){
  echo "<div id='content'>          
          <div id='content-detail'>";

$name=trim($_POST[name]);
$email=trim($_POST[email]);
$address=trim($_POST[address]);
$phone=trim($_POST[phone]);

if (empty($name)){
  echo "<span class='table8'>Anda belum mengisikan NAMA<br />
          <a href=javascript:history.go(-1)><b>Ulangi Lagi!</b>";
}
elseif (empty($email)){
  echo "<span class='table8'>Anda belum mengisikan EMAIL<br />
          <a href=javascript:history.go(-1)><b>Ulangi Lagi!</b>";
}
elseif (empty($address)){
  echo "<span class='table8'>Anda belum mengisikan SUBJEK<br />
          <a href=javascript:history.go(-1)><b>Ulangi Lagi!</b>";
}
elseif (empty($phone)){
  echo "<span class='table8'>Anda belum mengisikan PESAN<br />
          <a href=javascript:history.go(-1)><b>Ulangi Lagi!</b>";
}
else{
  if(!empty($_POST['kode'])){
    if($_POST['kode']==$_SESSION['captcha_session']){

      $sql="INSERT INTO customer(name,
                                   email,
                                   address,
                                   phone,
                                   tanggal,
                                   password) 
                        VALUES('$_POST[name]',
                               '$_POST[email]',
                               '$_POST[address]',
                               '$_POST[phone]',
                               '$tgl_sekarang',
                               md5('$_POST[password]'))";
      // echo $sql;
      mysql_query($sql);
      $sql="select max(id) as id from customer";
      $s=mysql_query($sql);
      $r=mysql_fetch_array($s);
      $_SESSION['id_customer']     = $r['id'];
  echo "<h4 class='heading colr'>Register Completed</h4></span><br /><br /><br /><br /><br /><br /><br /><br />"; 
  // echo "<span class='table8'><p align=center><div class='table5'><b>Terima kasih telah menghubungi kami. <br /> Kami akan segera meresponnya.</b></p>";
    }else{
      echo "<span class='table8'>Kode yang Anda masukkan tidak cocok<br />
            <a href=javascript:history.go(-1)><b>Ulangi Lagi</b></a>";
    }
  }else{
    echo "<span class='table8'>Anda belum memasukkan kode<br />
          <a href=javascript:history.go(-1)><b>Ulangi Lagi</b></a>";
  }
}
//   echo "</div>
// <div class='bottom_prod_box_big9'>
//     </div>";            
  // echo "<script>javascript:history.go(-1)</script>";
}

// Modul hubungi kami
else if ($_GET['module'] == 'hubungikami'){

  echo "<h4 class='heading colr'>Kontak Kami</h4>"; 
  echo "<b> Hubungi kami secara online dengan mengisi form di bawah ini:</b>
        <div class='table5'>
          <table width='100%' style='border: 0pt dashed #0000CC;padding: 10px;'>
          <form action=hubungi-aksi.html method=POST>
          <tr><td><span class='table4'>Nama:</td><td>  <input type=text class='isikoment3' name=nama size=40></td></tr>
          <tr><td><span class='table4'>Email:</td><td>  <input type=text class='isikoment3' name=email size=40></td></tr>
          <tr><td><span class='table4'>Subjek:</td><td>  <input type=text class='isikoment3' name=subjek size=55></td></tr>
          <tr><td valign=top><span class='table4'>Pesan:</td><td><textarea class='isikoment3' name=pesan  style='width: 315px; height: 100px;'></textarea></td></tr>
          <tr><td>&nbsp;</td><td><img src='captcha.php'></td></tr>
          <tr><td>&nbsp;</td><td><span class=isikomen>(masukkan 6 kode di atas)<br /><input type=text class='isikoment3' name=kode size=10 maxlength=6><br /></td></tr>
          </td><td colspan=2><p style='padding-top:15px ;'><input style=' width: 85px; height: 23px;' type=submit  class=simplebtn value='KIRIM PESAN'></td></tr>
          </form></table><br />
        </div>";
            
}

// Modul hubungi aksi
else if ($_GET['module']=='hubungiaksi'){
  echo "<div id='content'>          
          <div id='content-detail'>";

$nama=trim($_POST[nama]);
$email=trim($_POST[email]);
$subjek=trim($_POST[subjek]);
$pesan=trim($_POST[pesan]);

if (empty($nama)){
  echo "<span class='table8'>Anda belum mengisikan NAMA<br />
  	      <a href=javascript:history.go(-1)><b>Ulangi Lagi!</b>";
}
elseif (empty($email)){
  echo "<span class='table8'>Anda belum mengisikan EMAIL<br />
  	      <a href=javascript:history.go(-1)><b>Ulangi Lagi!</b>";
}
elseif (empty($subjek)){
  echo "<span class='table8'>Anda belum mengisikan SUBJEK<br />
  	      <a href=javascript:history.go(-1)><b>Ulangi Lagi!</b>";
}
elseif (empty($pesan)){
  echo "<span class='table8'>Anda belum mengisikan PESAN<br />
  	      <a href=javascript:history.go(-1)><b>Ulangi Lagi!</b>";
}
else{
	if(!empty($_POST['kode'])){
		if($_POST['kode']==$_SESSION['captcha_session']){

  mysql_query("INSERT INTO hubungi(nama,
                                   email,
                                   subjek,
                                   pesan,
                                   tanggal) 
                        VALUES('$_POST[nama]',
                               '$_POST[email]',
                               '$_POST[subjek]',
                               '$_POST[pesan]',
                               '$tgl_sekarang')");
  echo "<h4 class='heading colr'>Hubungi Kami</h4></span><br />"; 
  echo "<span class='table8'><p align=center><div class='table5'><b>Terima kasih telah menghubungi kami. <br /> Kami akan segera meresponnya.</b></p>";
		}else{
			echo "<span class='table8'>Kode yang Anda masukkan tidak cocok<br />
			      <a href=javascript:history.go(-1)><b>Ulangi Lagi</b></a>";
		}
	}else{
		echo "<span class='table8'>Anda belum memasukkan kode<br />
  	      <a href=javascript:history.go(-1)><b>Ulangi Lagi</b></a>";
	}
}
  echo "</div>
<div class='bottom_prod_box_big9'>
    </div>";            
}

// Modul blog
else if ($_GET['module']=='blog'){ ?>
    <div id="content">
        <!-- <div class="title">
          <h2>Berita</h2>
        </div> -->
    <?php
    $p = new pageNavi_All;
    $batas = 8;
    $posisi = $p->cariPosisi($batas);
    // Tampilkan semua berita
    $sql = mysql_query("SELECT * FROM berita  order by tanggal desc,jam desc LIMIT ".$posisi.",".$batas."");
      while($r = mysql_fetch_array($sql)){
      ?>
        <div id="post">
      <?php
            // Apabila ada gambar dalam berita, tampilkan
            if ($r['gambar']!='') {
            ?>
                <a class="thumb" href="berita-<?php echo $r['id_berita'] ?>-<?php echo $r['judul_seo'] ?>.html">
                <img width=150 height=105 src="<?php echo $f['folder'] ?>foto_produk/<?php echo $r['gambar'] ?>">
                </a>
            <?php } ?>
            <div class="content">
                <h3>
                <a class="ease" href="berita-<?php echo $r['id_berita'] . '-' .$r['judul_seo'] ?>.html"><?php echo $r['judul'] ?></a>
                </h3>
            <?php
                $tgl = tgl_indo($r['tanggal']);
                echo '<div class="post-meta">';
                echo $r['hari'] .', ' . $tgl . ' - ' . $r['jam'] .' WIB | ';
                echo '</div>';
                // Tampilkan hanya sebagian isi berita
                $isi_berita = htmlentities(strip_tags($r['isi_berita'])); // membuat paragraf pada isi berita dan mengabaikan tag html
                $isi = substr($isi_berita,0,180); // ambil sebanyak 180 karakter
                $isi = substr($isi_berita,0,strrpos($isi," ")); // potong per spasi kalimat
            ?>
                <p><?php echo $isi ?>... <a class="ease" href="berita-<?php echo $r['id_berita'] . '-' .$r['judul_seo'] ?>.html">Selengkapnya &rarr;</a></p>
            </div><!-- END #post .content -->
        </div><!-- END #post -->
<?php }

  $jmldata = mysql_num_rows(mysql_query("SELECT * FROM berita"));
  $jmlhalaman = $p->jumlahHalaman($jmldata, $batas);
  $linkHalaman = $p->navHalaman($_GET['halberita'], $jmlhalaman);
?>
  <!-- Page Navigation -->
  <div class="light">
        <div class="pageNavi">
      <?php echo $linkHalaman ?>
    </div>
  </div>      
  <!-- END Page Navigation -->
</div><!-- END #content -->
<?php 
}

// Modul hubungi aksi
else if ($_GET['module']=='detailberita'){ ?>
  <div id="content" style='min-height:400px'>          
    <?php
        $detail = mysql_query("SELECT * FROM berita    
                               WHERE 
                               id_berita = '".abs((int)$_GET['id'])."'");

        $d = mysql_fetch_array($detail);
        $tgl = tgl_indo($d['tanggal']);
        $baca = $d['dibaca'] + 1;
    ?>
        <div class="title">
            <h2><?php echo $d['judul'] ?></h2>
        </div>
    
        <div id="post">
        <?php
            echo '<div class="post-meta">';
            echo $d['hari'] .', ' . $tgl . ' - ' . $d['jam'] .' WIB <br/>';
            // echo 'Diposting oleh : <b>'.$d['nama_lengkap'].'</b> | ';
            // echo 'Kategori: <a class="ease" href="kategori-'.$d['id_kategori'].'-'.$d['kategori_seo'].'.html"><b>'.$d['nama_kategori'].'</b></a> - ';
            echo 'Dibaca: <b>'.$baca.'</b> kali<br/>';
            echo '</div>';

            // Share to Gmail, Email, Facebook, Twitter, etc
            echo "<div class='section'>    
                  <div class='addthis_toolbox addthis_default_style'>
                  <a class='addthis_button_preferred_1'></a>
                  <a class='addthis_button_preferred_2'></a>
                  <a class='addthis_button_preferred_3'></a>
                  <a class='addthis_button_preferred_4'></a>
                  <a class='addthis_button_compact'></a>
                  <a class='addthis_counter addthis_bubble_style'></a>
                  </div>
                  <script type='text/javascript' src='http://s7.addthis.com/js/250/addthis_widget.js#pubid=ra-4f8aab4674f1896a'></script>
                  </div>";
                  
            // Apabila ada gambar dalam berita, tampilkan   
            if($d['gambar'] != '') {
        ?>
            <img style="float:left; padding: 7px 10px 7px 0;" src="config/timthumb.php?src=foto_berita/<?php echo $d['gambar'] ?>&amp;w=200&amp;h=150">
            <?php
            }
            //$isi_berita=nl2br($d[isi_berita]); // membuat paragraf pada isi berita
            echo $d['isi_berita'];

            //dapatkan nama domain
            // $domain=mysql_fetch_array(mysql_query("SELECT alamat_website FROM identitas"));
            
            //tombol like fb
            // $base_url = "http://kakillimaweb.com/";
            // echo "<div class='fb-like' data-href='$domain[alamat_website]/berita-$d[id_berita]-$d[judul_seo].html' data-send='true' data-show-faces='true' data-width='600'></div>";

           // echo "<iframe src=\"https://www.facebook.com/plugins/like.php?href=".$base_url."berita-$d[id_berita]-$d[judul_seo].html&amp;show_faces=true\" 
             //     scrolling=\"no\" frameborder=\"0\" style=\"border:none; width:450px; height:80px\"></iframe>"; 
            ?>
        
        </div>
  
        <?php       
        // pisahkan kata per kalimat lalu hitung jumlah kata
        $pisah_kata  = explode(",",$d['tag']);
        $jml_katakan = (integer)count($pisah_kata);
    
        $jml_kata = $jml_katakan - 1; 
        $ambil_id = abs((int)$_GET['id']);
        // $ambil_id = substr($val->validasi($_GET['id'],'sql'),0,4);
    
        // Looping query sebanyak jml_kata
        $cari = "SELECT * FROM berita WHERE (id_berita<'$ambil_id') and (id_berita!='$ambil_id') and (" ;
        for ($i = 0; $i <= $jml_kata; $i++){
            $cari .= "tag LIKE '%$pisah_kata[$i]%'";
            if ($i < $jml_kata ){
                $cari .= " OR ";
            }
        }
        $cari .= ") ORDER BY id_berita DESC LIMIT 5";
     
        $hasil  = mysql_query($cari);
        echo '<div id="related-post">';
            echo '<h3>Berita Terkait</h3>';
            while($h = mysql_fetch_array($hasil)){
                    echo '<a class="ease" href="berita-'.$h['id_berita'].'-'.$h['judul_seo'].'.html">';
          echo '<div class="related">';
                    echo '<img style="float:left; padding: 5px 10px 5px 0;" src="config/timthumb.php?src=foto_berita/'.$h['gambar'].'&amp;w=100&amp;h=80">';
                    echo '<h3>'.$h['judul'].'</h3>';
          echo '</div>';
          echo '</a>';
            }
        echo "</div>";
    echo '<div class="clearboth"></div>';
  echo '</div>';
  
  // Apabila detail berita dilihat, maka tambahkan berapa kali dibacanya
  mysql_query("UPDATE berita SET dibaca = '".$baca."' WHERE id_berita = '".$ambil_id."'"); 
}

// Modul hasil pencarian produk 
else if ($_GET['module']=='hasilcari'){
  // menghilangkan spasi di kiri dan kanannya
  $kata = trim($_POST['kata']);
  // mencegah XSS
  $kata = htmlentities(htmlspecialchars($kata), ENT_QUOTES);

  // pisahkan kata per kalimat lalu hitung jumlah kata
  $pisah_kata = explode(" ",$kata);
  $jml_katakan = (integer)count($pisah_kata);
  $jml_kata = $jml_katakan-1;

  $cari = "SELECT * FROM produk WHERE " ;
    for ($i=0; $i<=$jml_kata; $i++){
      $cari .= "deskripsi LIKE '%$pisah_kata[$i]%' OR nama_produk LIKE '%$pisah_kata[$i]%'";
      if ($i < $jml_kata ){
        $cari .= " OR ";
      }
    }
  $cari .= " ORDER BY id_produk DESC LIMIT 6";
  $hasil  = mysql_query($cari);
  $ketemu = mysql_num_rows($hasil);

  echo "<h4 class='heading colr'>Hasil Pencarian</h4>";

  if ($ketemu > 0){
  echo "<div class='table3'>Ditemukan <b>$ketemu</b> produk dengan kata <font style='background-color:#D5F1FF'><b>$kata</b></font> <b>:</b> </div>";
    while($t=mysql_fetch_array($hasil)){
      // Tampilkan hanya sebagian isi produk
      $isi_produk = htmlentities(strip_tags($t['deskripsi'])); // mengabaikan tag html
      $isi = substr($isi_produk,0,250); // ambil sebanyak 250 karakter
      $isi = substr($isi_produk,0,strrpos($isi," ")); // potong per spasi kalimat
    	  echo "<div class='prod_box_big'>
        	<div class='top_prod_box_big'></div>
        <div class='center_prod_box_big'>            
          <div class='details_big_cari'>
            <div class='product_title_big'><a href=produk-$t[id_produk]-$t[produk_seo].html>$t[nama_produk]</a></div>
            $isi ... <a href=produk-$t[id_produk]-$t[produk_seo].html><span class='table6'>selengkapnya</a>
	
	      </div>
          </div> 
          </div>
          </div>    
          <span class='bottom_prod_box_big_yacari'></div>"; 
      }        
    }                                                          
  else{
    echo "<p><div class='table3'>Tidak ditemukan produk dengan kata <font style='background-color:#D5F1FF'><b>$kata</b></p>
	
	 <div class='bottom_prod_box_big_nocari'></div>";
  }
}


// Modul selesai belanja
else if ($_GET['module']=='selesaibelanja'){
  $sid = session_id();
  $sql = mysql_query("SELECT * FROM orders_temp, produk 
			                WHERE id_session='$sid' AND orders_temp.id_produk=produk.id_produk");
  $ketemu   = mysql_num_rows($sql);
  
  if($ketemu < 1) {
   echo "<script> alert('Keranjang belanja masih kosong');window.location='index.php'</script>\n";
   	 exit(0);
	} else {
    if(isset($_SESSION['id_customer']) && $_SESSION['id_customer']!=0){
        $sql2="select * from customer where id=".$_SESSION['id_customer'];
        $s2=mysql_query($sql2);
        $r2=mysql_fetch_array($s2);
        $name=$r2['name'];
        $address=$r2['address'];
        $phone=$r2['phone'];
        $email=$r2['email'];
    }else{
        $name='';
        $address='';
        $phone='';
        $email='';
    }
  echo "<h4 class='heading colr'>Check Out</h4>
      <form name=form action=simpan-transaksi.html method=POST onSubmit=\"return validasi(this)\">
      <table width=650>
      <tr><td><span class='table4'>Name</td><td>  <input type=text name=nama value=$name size=30 class='table5'></td></tr>
      <tr><td><span class='table4'>Address</td><td>  <input type=text name=alamat value=$address size=70 class='table5'></td></tr>
      <tr><td><span class='table4'>Phone</td><td>  <input type=text name=telpon value=$phone class='table5'></td></tr>
      <tr><td><span class='table4'>Email</td><td>  <input type=text name=email value=$email class='table5'></td></tr>
      <tr><td valign=top><span class='table4'>Service Delivery</td><td>  
          <select name='jasa' id='jasa' class='table5'>
          <option value='0' selected>- Select Type Delivery Service -</option>";
          $tampil=mysql_query("SELECT * FROM shop_pengiriman ORDER BY nama_perusahaan");
          while($r=mysql_fetch_array($tampil)){
             echo "<option value='$r[id_perusahaan]'>$r[nama_perusahaan]</option>";
          }
      echo "</select></td></tr>
      <tr>
		<td><span class='table4'>Destination City</td>
		<td> <span id='kota'>
			<select name='kota' id='kota' class='table5'>
				<option value='0' selected>Determine the type Formerly Services Delivery</option>
			</select>
			</span>
		</td>
	  </tr>
      <tr><td colspan=2><input style='width: 60px; height: 25px;' type=submit class= simplebtn value=PROCESS></td></tr>
      </table><br /><br />";
		  
     echo "<h4 class='heading colr'>Confirm your Shopping Cart</h4>
          <table width=670 border=0 cellpadding=0 cellspacing=1 align=center>
          <tbody>
          <tr background='images/bg_tab.jpg' align=center height=23>
			<th><span class='table'>No</th><th><span class='table'>Product Name</th>
			<th><span class='table'>Weight (Kg)</th><th><span class='table'>Qty</th>
          <th><span class='table'>Price</th><th><span class='table'>Sub Total</th></tr>";  
  
  $no=1;
  while($r=mysql_fetch_array($sql)){
  //START nampilkan diskon per produk --    
    $disc        = ($r[diskon]/100)*$r[harga];
    $hargadisc   = number_format(($r[harga]-$disc),0,",","."); 
    $subtotal    = ($r[harga]-$disc) * $r[jumlah];
//END nampilkan diskon per produk --
    $total       = $total + $subtotal;  
    $subtotal_rp = format_rupiah($subtotal);
    $total_rp    = format_rupiah($total);
    $harga       = format_rupiah($r['harga']);
    $subtotalberat = $r['berat'] * $r['jumlah']; // total berat per item produk 
    $totalberat  = $totalberat + $subtotalberat; // grand total berat all produk yang dibeli    
    echo "<tr background='images/bg_tab2.jpg' align=center height=23><td><span class='table2'>$no</td><input type=hidden name=id[$no] value=$r[id_orders_temp]>
              <td><span class='table2'>$r[nama_produk]</td>
       			  <td align=center><span class='table2'>$r[berat]</td>
              <td align=center><span class='table2'>$r[jumlah]</td>
              <td><span class='table2'>$harga</td>
              <td><span class='table2'>$subtotal_rp</td>
          </tr>";
    $no++; 
  }
  echo "<tr><td colspan=2 align=right><span class='table3'>Total Weight:</td><td align=center><span class='table3'>$totalberat kg</b></td>
            <td align=right colspan=2><span class='table3'>Total Price:</td><td align=center><span class='table3'>Rp. $total_rp,-</td></tr>
        </tbody></table>";
		
    echo "<div class='prod_box_big'>
        	<div class='top_prod_box_big'></div>
          <div class='center_prod_box_big'>            
          <div class='details_big_cari'><div>
		  <table width=520><tr><td>
		  <input style='width: 70px; height: 22px;'  class= simplebtn type=button value='BACK' onclick=self.history.back()>
          <span style='float : right;'><input style='width: 110px; height: 22px;' type=submit  class= simplebtn value='PROSES'></span>
		  </td></tr></table>
          </div></div></div>
        <div class='bottom_prod_box_bigx'></div>
        </div>";        
  }
}      


// Modul simpan transaksi
else if ($_GET['module']=='simpantransaksi') {
  $kar1   = strstr($_POST['email'], "@");
  $kar2   = strstr($_POST['email'], ".");
  $name  = $_POST['nama'];
  
  if (empty($_POST['nama']) || empty($_POST['alamat']) || empty($_POST['telpon']) || empty($_POST['email']) || empty($_POST['kota'])) {
    echo "The data you enter is not yet complete<br />
    	    <a href='selesai-belanja.html'><b>Try Again</b>";
  }
  else if (preg_match("[a-z|A-Z]",$name)) {
    echo "The name should not be filled with numbers or symbols.<br />
   	      <a href=javascript:history.go(-1)><b>Try Again</b></a>";
  }
  else if (strlen($kar1)==0 OR strlen($kar2)==0) {
    echo "Your email address is not valid, possibly lacking a dot (.) Or the @ sign.<br />
   	      <a href=javascript:history.go(-1)><b>Try Again</b></a>";
  } else {
	// fungsi untuk mendapatkan isi keranjang belanja
	function isi_keranjang() {
		$isikeranjang = array();
		$sid = session_id();
		$sql = mysql_query("SELECT * FROM orders_temp WHERE id_session='$sid'");
		
		while ($r=mysql_fetch_array($sql)) {
			$isikeranjang[] = $r;
		}
		return $isikeranjang;
	}

	$tgl_skrg = date("Ymd");
	$jam_skrg = date("H:i:s");

	// simpan data pemesanan 
	mysql_query("INSERT INTO orders(nama_kustomer, alamat, telpon, email, tgl_order, jam_order, id_kota) 
				 VALUES('$_POST[nama]','$_POST[alamat]','$_POST[telpon]','$_POST[email]','$tgl_skrg','$jam_skrg','$_POST[kota]')");
	  
	// mendapatkan nomor orders
	$id_orders = mysql_insert_id();

	// panggil fungsi isi_keranjang dan hitung jumlah produk yang dipesan
	$isikeranjang = isi_keranjang();
	$jml          = count($isikeranjang);

	// simpan data detail pemesanan  
	for ($i = 0; $i < $jml; $i++) {
	  mysql_query("INSERT INTO orders_detail(id_orders, id_produk, jumlah) 
				   VALUES('$id_orders',{$isikeranjang[$i]['id_produk']}, {$isikeranjang[$i]['jumlah']})");
	}
  
	// setelah data pemesanan tersimpan, hapus data pemesanan di tabel pemesanan sementara (orders_temp)
	for ($i = 0; $i < $jml; $i++) {
	  mysql_query("DELETE FROM orders_temp
					 WHERE id_orders_temp = {$isikeranjang[$i]['id_orders_temp']}");
	}

  echo "<h4 class='heading colr'>Transaction Process Completed</h4>";
  echo "<div class='prod_box_big'>
        	<div class='top_prod_box_big'></div>
			<div class='center_prod_box_big'>            
				<div class='details_big_cari'>
					<div>
      Customer data along with its order is as follows: <br />
      <table>
      <tr><td>Name           </td><td> : <b>$_POST[nama]</b> </td></tr>
      <tr><td>Address </td><td> : $_POST[alamat] </td></tr>
      <tr><td>Telephone         </td><td> : $_POST[telpon] </td></tr>
      <tr><td>E-mail         </td><td> : $_POST[email] </td></tr></table><br />
      
      Order Number: <b> <span class='table6'>$id_orders</b><br /><br />";

      $daftarproduk = mysql_query("SELECT * FROM orders_detail,produk 
                                 WHERE orders_detail.id_produk=produk.id_produk 
                                 AND id_orders='$id_orders'");

echo "<table width=600 border=0 cellpadding=0 cellspacing=1 align=center>
        <tr background='images/bg_tab3.jpg' align=center height=23><th><span class='table'>No</th><th><span class='table'>Product Name</th><th><span class='table'>Weight(Kg)</th><th><span class='table'>Qty</th><th><span class='table'>Price</th><th><span class='table'>Sub Total</th></tr>";
      
$pesan = "Thank you for an online order at our store<br /><br />  
          Name: $_POST[nama] <br />
          Address: $_POST[alamat] <br/>
          Telephone: $_POST[telpon] <br /><hr />
          
          Order Number: $id_orders <br />
          Your order data is as follows: <br /><br />";
        
$no=1;
while ($d=mysql_fetch_array($daftarproduk)) {
   $subtotalberat = $d[berat] * $d[jumlah]; // total berat per item produk 
   $totalberat    = $totalberat + $subtotalberat; // grand total berat all produk yang dibeli
   $disc          = ($d[diskon]/100)*$d[harga];
   $hargadisc     = number_format(($d[harga]-$disc),0,",","."); 
   $subtotal      = ($d[harga]-$disc) * $d[jumlah];

   $total       = $total + $subtotal;
   $subtotal_rp = format_rupiah($subtotal);    
   $total_rp    = format_rupiah($total);    
   $harga       = format_rupiah($d['harga']);

   echo "<tr background='images/bg_tab2.jpg' align=center height=23><td>$no</td><td>$d[nama_produk]</td><td align=center>$d[berat]</td><td align=center>$d[jumlah]</td><td>Rp. $harga,-</td><td>Rp. $subtotal_rp,-</td></tr>";

   $pesan.="$d[jumlah] $d[nama_produk] -> Rp. $harga -> Subtotal: Rp. $subtotal_rp <br />";
   $no++;
}

$ongkos       = mysql_fetch_array(mysql_query("SELECT ongkos_kirim FROM kota WHERE id_kota='$_POST[kota]'"));
$ongkoskirim1 = $ongkos[ongkos_kirim];
$ongkoskirim  = $ongkoskirim1 * $totalberat;

$grandtotal   = $total + $ongkoskirim; 

$ongkoskirim_rp   = format_rupiah($ongkoskirim);
$ongkoskirim1_rp  = format_rupiah($ongkoskirim1); 
$grandtotal_rp    = format_rupiah($grandtotal);  

$pesan .= "<br /><br />Total : Rp. $total_rp,-
           <br />Shipping to Purpose Your City : Rp. $ongkoskirim1_rp/Kg 
           <br />Total Weight : $totalberat Kg
           <br />Total Shipping  : Rp. $ongkoskirim_rp		 
           <br />Grand Total : Rp. $grandtotal_rp,-
           <br /><br />Please make payment to the bank listed as Grand total, account number <b>0312849389</b> a.n. Niken Sulanjari";

$subjek="Pemesanan Online Whattowearstyle";

// Kirim email dalam format HTML
$dari   = "From: info@kakilimaweb.com \n";
$dari  .= "Content-type: text/html \r\n";

// Kirim email ke kustomer
mail($_POST[email],$subjek,$pesan,$dari);


// Kirim email ke pengelola toko online
mail("info@kakilimaweb.com",$subjek,$pesan,$dari);

echo "<tr><td colspan=5 align=right>Total : Rp. </td><td align=right><b>$total_rp</b></td></tr>
      <tr><td colspan=5 align=right>Shipping to Purpose Your City: Rp. </td><td align=right><b>$ongkoskirim1_rp</b>/Kg</td></tr>      
	    <tr><td colspan=5 align=right>Total Weight : </td><td align=right><b>$totalberat Kg</b></td></tr>
      <tr><td colspan=5 align=right>Total Shipping : Rp. </td><td align=right><b>$ongkoskirim_rp</b></td></tr>      
      <tr><td colspan=5 align=right>Grand Total : Rp. </td><td align=right><b>$grandtotal_rp</b></td></tr>
      </table>";
echo "<br /><br /><br /><br /><p>- Data transfer orders and account number has been sent to your email. <br />
               - If you do not make payment within 3 days, then the data will be erased your order (transaction canceled)</p><br />      
              </div>
          </div>    
          </div>
            <div class='bottom_prod_box_big10'></div>
          </div>";    
}
} 


?>
